﻿@using Orchard.Core.Shapes.Localization
@using System.Globalization

@{

    // prevent the shape from being rendered twice in a page
    if (WorkContext.GetState<object>("TimePickerLocalization") != null) {
        return;
    }

    WorkContext.SetState("TimePickerLocalization", new object());

    Style.Require("jQueryUI_TimePicker");
    Script.Require("jQueryUI_TimePicker");

    var cultureInfo = CultureInfo.GetCultureInfo(WorkContext.CurrentCulture);

    var timeFormat = cultureInfo.DateTimeFormat.ShortTimePattern
        .Replace("H", "h");

    var ampm = cultureInfo.DateTimeFormat.ShortTimePattern.Contains("H") ? "false" : "true";
}

<script type="text/javascript">
//<![CDATA[
    $(function() {

        $.timepicker.regional[''] = {
            timeOnlyTitle: '@HttpUtility.JavaScriptStringEncode(T("Choose time").Text)',
            timeText: '@HttpUtility.JavaScriptStringEncode(T("Time").Text)',
            hourText: '@HttpUtility.JavaScriptStringEncode(T("Hour").Text)',
            minuteText: '@HttpUtility.JavaScriptStringEncode(T("Minute").Text)',
            currentText: '@HttpUtility.JavaScriptStringEncode(T("Now").Text)', // Display text for current time link
            closeText: '@HttpUtility.JavaScriptStringEncode(T("Done").Text)', // Display text for close link
            timeFormat: '@HttpUtility.JavaScriptStringEncode(timeFormat)',
            amNames: ['@cultureInfo.DateTimeFormat.AMDesignator', 'AM', 'A'],
            pmNames: ['@cultureInfo.DateTimeFormat.PMDesignator', 'PM', 'P'],
            ampm: @ampm,
            isRTL: @(cultureInfo.TextInfo.IsRightToLeft ? "true" : "false")
        };

        $.timepicker.setDefaults($.timepicker.regional['']);
    })
//]]>
</script>